import axios from "axios"
let instance = axios.create({});

//请求拦截器
instance.interceptors.request.use(
    config=>{
        if (localStorage.getItem("token")!=null) {
            config.headers.token = localStorage.getItem("token");
        }
        return config;
    }
)
export default{
    get_category(){
        return axios({
            method:'get',
            url:'http://localhost:8090/category/xixi',
        });
    },
    get_books_by_category(category){
        return axios({
            
                method: 'get',
                url: "http://localhost:8090/book/getbook_categroy?category="+category,

            });
    },
    get_allbook(){
        return axios.get("http://localhost:8090/book/all"); 
    },
    get_newpage(id)
    {
        return axios.get("http://localhost:8090/book/getbook_id?id="+id);
    },
    get_category_by_id(id)
    {
        return axios.get("http://localhost:8090/category/getcategory_by_id?id="+id);
    },
    get_book_by_name(name)
    {
       return axios({
           method:'post',
           url:"http://localhost:8090/book/getbook_name",
           data:{
               name:name
           }
       });
       
    },
    login_request(username,password)
    {
        return axios({
            method:'post',
            url:"http://localhost:8090/user/login",
            data:{
                username:username,
                password:password,
            }

        })
    },
  getcollect(book_id,user_id)//判断收藏状态
     {
         return axios({
             method:'post',
            url:"http://localhost:8090/user/collect",
             data:{
                 book_id:book_id,
                 user_id:user_id,
            }
         })
     },

    
   
    add(user_id,book_id)
      {
        return instance.get("http://localhost:8090/user/add?user_id="+user_id+"&book_id="+book_id);
      },
    remove(user_id,book_id)
    {
        return instance.get("http://localhost:8090/user/remove?user_id="+user_id+"&book_id="+book_id);
    },
    getlove_book(id)
    {
        return instance.get("http://localhost:8090/user/getlovebook?id="+id);
            
    },
    
}